package com.horoscope.astrology.zodiac.signs.free.utils.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.horoscope.astrology.zodiac.signs.free.R
import com.jeremyliao.liveeventbus.LiveEventBus
import com.zyyoona7.wheel.WheelView
import kotlinx.android.synthetic.main.dialog_select_gender_or_status.*

/**
 *  作者    1024
 *  时间    2020-02-05 15:28
 *  文件    constellation-android
 *  描述    gender 和 status dialog
 */
class DialogSelectGenderOrStatus(private val tag: Int,private val className:String) : BaseDialogFragment() {

    private lateinit var data: WheelView<String>

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(view)
    }

    private fun initView(view: View) {
        data = view.findViewById(R.id.wheel_view_gender)
        setWheelView(data, initData())
        done?.setOnClickListener {
            LiveEventBus.get("Done$className", String::class.java).post(getSelect())
        }
    }

    /**
     * tag -> 1 gender
     * tag -> 2 status
     */
    private fun initData(): ArrayList<String> {
        val list = ArrayList<String>()
        list.clear()
        if (tag == 1) {
            list.add("Male")
            list.add("Female")
        } else {
            list.add("Single")
            list.add("Soulmate")
            list.add("Married")
            list.add("Difficult")
        }
        return list
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_select_gender_or_status, container, false)
    }

    // 返回选中的数据
    fun getSelect(): String {
        return data.selectedItemData
    }
}